<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>登录界面</title>
    <link rel="stylesheet" href="css/index.css" />
    <script src="js/jquery-1.11.3.min.js"></script>
  </head>
  <body>
    <!-- 登录界面 -->
    <div class="load">
      <div class="header">
        <div><a href="#">账户登录</a></div>
      </div>
      <div class="one">
        <input class="account" id="id" type="text" placeholder="手机号/用户名/邮箱" />
      </div>
      <div class="two">
        <input class="password" id="password" type="password" placeholder="密码" />
      </div>
      <div class="user-select">
        <input id="user" type="radio" name="identity"  value="user"/><label for="user">用户</label>
        <input  id="seller" type="radio" name="identity"  value="seller"/><label for="seller"> 商家</label>
        <input id="admin" type="radio" name="identity"  value="admin"/><label for="admin"> 管理员</label>
      </div>
  <div class="load-button" onclick="login()" style="cursor: pointer">
    <a>登录</a>
  </div>

  <div class="load-select">
    <a href="#" id="Register">免费注册</a>
  </div>
</div>
<!-- 注册界面 -->
<div class="register">
  <div class="rheader">
    <span>会员注册</span>
    <span>已注册可</span>
    <a href="#" id="Load">直接登录</a>
  </div>
  <div class="a"><input id="tele" class="ia" type="text" placeholder="请输入手机号码"></div>
  <div class="a"><input id="username" class="ia" type="text" placeholder="请输入用户昵称"></div>
    <div class="a"><input id="address" class="ia" type="text" placeholder="请输入地址"></div>
  <div class="c"><input id="userpassword" class="ic" type="text" placeholder="密码由8-20位字母，数字和符号组成"></div>
  <div class="d"><input id="repassword" class="id" type="text" placeholder="请再次输入上面的密码"></div>
  <div class="ruser-select">
    <input id="ruser" type="radio" name="rsame">
    <label for="ruser"> 用户</label>
    <input id="rseller" type="radio" name="rsame">
    <label for="rseller"> 商家</label>
  </div>
  <div class="protocal">
    <input type="checkbox">&nbsp;<span>我已经阅读并接受以下条款：《 <a href="#">我拼了服务条款</a> 》《 <a href="#">隐私条款</a> 》</span>
  </div>
  <div class="register-button" onclick="uregister()">
    <a href="#">立即注册</a>
  </div>
</div>
<script src="js/index.js"></script>
<script>
  function login(){
    let id = document.getElementById("id").value;
    let password = document.getElementById("password").value;
    let identity = $("input[name='identity']:checked").val();
    $.get("http://47.94.138.204:7790/example/login", { id: id, password: password, identity: identity },
            function(data){
              if(data == 1){
                if(identity == "seller")
                {
                   window.location.href = "seller_main.html";
                  localStorage.setItem("seller_id", id);
                }else if(identity == "user")
                {
                  window.location.href ="searchgoods.html";
                  localStorage.setItem("user_id",id);
                }else
                {
                  window.location.href="admin_main.html";
                  localStorage.setItem("admin_id",id);
                }

              }else{
                if(data==2)
                {
                  alert("账号被封禁");
                }
                else
                {
                  alert("输入的账号不存在或密码错误");
                }
              }
            });
  }
  function uregister()
  {
    let tele=document.getElementById("tele").value;
    let username=document.getElementById("username").value;
    let address=document.getElementById("address").value;
    let userpassword=document.getElementById("userpassword").value;
    let repassword=document.getElementById("repassword").value;
    let uidentity=$("input[name='rsame']:checked").val();
    if(userpassword != repassword)
    {
      alert("两次密码不相同")
      return 0;
    }
    else
    {
      $.get("http://47.94.138.204:7790/example/add", { username: username, password: userpassword, identity: uidentity ,address: address ,tele:tele ,root:'0'},
              function(data){
                if(data == 1){
                  alert("注册成功");
                }else{
                  alert("xxxx");
                }
              });
    }
  }
</script>
</body>
</html>
